Predicting when does the algae blossoms algaeDataset is our Dataset name

library(DMwR)
## Loading required package: lattice
## Loading required package: grid
algaeDataset <- algae

From the below summary we can observe that during the winter season maximum water samples has been taken, also from the chemical parameters summary we undertand that we have some NA’s value

summary(algaeDataset)
##     season       size       speed         mxPH            mnO2       
##  autumn:40   large :45   high  :84   Min.   :5.600   Min.   : 1.500  
##  spring:53   medium:84   low   :33   1st Qu.:7.700   1st Qu.: 7.725  
##  summer:45   small :71   medium:83   Median :8.060   Median : 9.800  
##  winter:62                           Mean   :8.012   Mean   : 9.118  
##                                      3rd Qu.:8.400   3rd Qu.:10.800  
##                                      Max.   :9.700   Max.   :13.400  
##                                      NA's   :1       NA's   :2       
##        Cl               NO3              NH4                oPO4       
##  Min.   :  0.222   Min.   : 0.050   Min.   :    5.00   Min.   :  1.00  
##  1st Qu.: 10.981   1st Qu.: 1.296   1st Qu.:   38.33   1st Qu.: 15.70  
##  Median : 32.730   Median : 2.675   Median :  103.17   Median : 40.15  
##  Mean   : 43.636   Mean   : 3.282   Mean   :  501.30   Mean   : 73.59  
##  3rd Qu.: 57.824   3rd Qu.: 4.446   3rd Qu.:  226.95   3rd Qu.: 99.33  
##  Max.   :391.500   Max.   :45.650   Max.   :24064.00   Max.   :564.60  
##  NA's   :10        NA's   :2        NA's   :2          NA's   :2       
##       PO4              Chla               a1              a2        
##  Min.   :  1.00   Min.   :  0.200   Min.   : 0.00   Min.   : 0.000  
##  1st Qu.: 41.38   1st Qu.:  2.000   1st Qu.: 1.50   1st Qu.: 0.000  
##  Median :103.29   Median :  5.475   Median : 6.95   Median : 3.000  
##  Mean   :137.88   Mean   : 13.971   Mean   :16.92   Mean   : 7.458  
##  3rd Qu.:213.75   3rd Qu.: 18.308   3rd Qu.:24.80   3rd Qu.:11.375  
##  Max.   :771.60   Max.   :110.456   Max.   :89.80   Max.   :72.600  
##  NA's   :2        NA's   :12                                        
##        a3               a4               a5               a6        
##  Min.   : 0.000   Min.   : 0.000   Min.   : 0.000   Min.   : 0.000  
##  1st Qu.: 0.000   1st Qu.: 0.000   1st Qu.: 0.000   1st Qu.: 0.000  
##  Median : 1.550   Median : 0.000   Median : 1.900   Median : 0.000  
##  Mean   : 4.309   Mean   : 1.992   Mean   : 5.064   Mean   : 5.964  
##  3rd Qu.: 4.925   3rd Qu.: 2.400   3rd Qu.: 7.500   3rd Qu.: 6.925  
##  Max.   :42.800   Max.   :44.600   Max.   :44.400   Max.   :77.600  
##                                                                     
##        a7        
##  Min.   : 0.000  
##  1st Qu.: 0.000  
##  Median : 1.000  
##  Mean   : 2.495  
##  3rd Qu.: 2.400  
##  Max.   :31.600  
## 

Removing the NA from the dataset

algaeDataset <- na.omit(algaeDataset)
summary(algaeDataset)
##     season       size       speed         mxPH            mnO2       
##  autumn:36   large :42   high  :76   Min.   :7.000   Min.   : 1.500  
##  spring:48   medium:83   low   :31   1st Qu.:7.777   1st Qu.: 7.675  
##  summer:43   small :59   medium:77   Median :8.100   Median : 9.750  
##  winter:57                           Mean   :8.078   Mean   : 9.019  
##                                      3rd Qu.:8.400   3rd Qu.:10.700  
##                                      Max.   :9.500   Max.   :13.400  
##        Cl              NO3              NH4                oPO4       
##  Min.   :  0.80   Min.   : 0.050   Min.   :    5.80   Min.   :  1.25  
##  1st Qu.: 11.85   1st Qu.: 1.364   1st Qu.:   49.38   1st Qu.: 18.56  
##  Median : 35.08   Median : 2.820   Median :  115.71   Median : 46.28  
##  Mean   : 44.88   Mean   : 3.384   Mean   :  537.67   Mean   : 78.27  
##  3rd Qu.: 58.52   3rd Qu.: 4.540   3rd Qu.:  235.25   3rd Qu.:102.83  
##  Max.   :391.50   Max.   :45.650   Max.   :24064.00   Max.   :564.60  
##       PO4              Chla               a1              a2        
##  Min.   :  2.50   Min.   :  0.200   Min.   : 0.00   Min.   : 0.000  
##  1st Qu.: 50.34   1st Qu.:  2.075   1st Qu.: 1.40   1st Qu.: 0.000  
##  Median :115.60   Median :  5.522   Median : 4.85   Median : 3.600  
##  Mean   :146.58   Mean   : 13.883   Mean   :15.32   Mean   : 7.777  
##  3rd Qu.:220.25   3rd Qu.: 18.308   3rd Qu.:19.32   3rd Qu.:11.700  
##  Max.   :771.60   Max.   :110.456   Max.   :89.80   Max.   :72.600  
##        a3               a4               a5               a6        
##  Min.   : 0.000   Min.   : 0.000   Min.   : 0.000   Min.   : 0.000  
##  1st Qu.: 0.000   1st Qu.: 0.000   1st Qu.: 0.000   1st Qu.: 0.000  
##  Median : 1.700   Median : 0.000   Median : 2.650   Median : 0.000  
##  Mean   : 4.613   Mean   : 1.846   Mean   : 5.493   Mean   : 6.447  
##  3rd Qu.: 5.525   3rd Qu.: 2.425   3rd Qu.: 8.000   3rd Qu.: 7.975  
##  Max.   :42.800   Max.   :44.600   Max.   :44.400   Max.   :77.600  
##        a7        
##  Min.   : 0.000  
##  1st Qu.: 0.000  
##  Median : 1.000  
##  Mean   : 2.665  
##  3rd Qu.: 2.700  
##  Max.   :31.600

Visualizing the algae blossoms

From this histogram we come to know that during winter season maximum PH is been recorded

library(ggplot2)
ggplot(algaeDataset,aes(mxPH,fill = season)) + geom_histogram(colour = "black")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

As we can see from the boxplot, we have a lot of outliers thus concluding that these values must have a lot of effect on the orthophoshate chemical count of the river

boxplot(algaeDataset$oPO4, ylab="Orthophosphate Count")

As we can see from the below graph that maximum times when the size of the river is medium we have taken the samples to identify the algae blossoms

ggplot(algaeDataset,aes(x=size)) + geom_bar(colour = "Red")

Here we are doing a bivariate boxplot which is helping us to understand about algae 1 that in what kind of the size of the river does it blossom more, so here we say that when the river size is small algae 1 blossoms a lot and we also see lot of outliers river size is medium

Similarily by looking at the other bivariate boxplots graphs we can summarize the below for all the other 6 different types algaes with respect to river size,season,speed components: Algae2 = medium,summer,low Algae3 = medium,spring, medium Algae4 = medium,spring, medium Algae5 = medium, summer, medium Algae6 = medium, autumn, medium Alage7 = medium, autumn, medium

library(lattice)
library(Hmisc)
## Warning: package 'Hmisc' was built under R version 3.5.2
## Loading required package: survival
## Loading required package: Formula
## 
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
## 
##     format.pval, units
bwplot(size~a1,data=algaeDataset,xlab = "Algae A1",ylab = "River size")

bwplot(season~a1,data=algaeDataset,xlab = "Algae A1",ylab = "Season")

bwplot(speed~a1,data=algaeDataset,xlab = "Algae A1",ylab = "River speed")

bwplot(size ~ a1,data=algae,panel=panel.bpplot,probs=seq(.01,.49,by=.01),datadensity=TRUE,ylab='River Size',xlab='Algal A1')

bwplot(size~a2,data=algaeDataset,xlab = "Algae A2",ylab = "River size")

bwplot(season~a2,data=algaeDataset,xlab = "Algae A2",ylab = "Season")

bwplot(speed~a2,data=algaeDataset,xlab = "Algae A2",ylab = "River speed")

bwplot(size~a3,data=algaeDataset,xlab = "Algae A3",ylab = "River size")

bwplot(season~a3,data=algaeDataset,xlab = "Algae A3",ylab = "Season")

bwplot(speed~a3,data=algaeDataset,xlab = "Algae A3",ylab = "River speed")

bwplot(size~a4,data=algaeDataset,xlab = "Algae A4",ylab = "River size")

bwplot(season~a4,data=algaeDataset,xlab = "Algae A4",ylab = "Season")

bwplot(speed~a4,data=algaeDataset,xlab = "Algae A4",ylab = "River speed")

bwplot(size~a5,data=algaeDataset,xlab = "Algae A5",ylab = "River size")

bwplot(season~a5,data=algaeDataset,xlab = "Algae A5",ylab = "Season")

bwplot(speed~a5,data=algaeDataset,xlab = "Algae A5",ylab = "River speed")

bwplot(size~a6,data=algaeDataset,xlab = "Algae A6",ylab = "River size")

bwplot(season~a6,data=algaeDataset,xlab = "Algae A6",ylab = "Season")

bwplot(speed~a6,data=algaeDataset,xlab = "Algae A6",ylab = "River speed")

bwplot(size~a7,data=algaeDataset,xlab = "Algae A7",ylab = "River size")

bwplot(season~a7,data=algaeDataset,xlab = "Algae A7",ylab = "Season")

bwplot(speed~a7,data=algaeDataset,xlab = "Algae A7",ylab = "River speed")

plot(algaeDataset$a1 ~ algaeDataset$Cl)

Multivariate Normal distribution check:

Here we have calculated covriance and column Means for the normal distribution check

colnames(algaeDataset)
##  [1] "season" "size"   "speed"  "mxPH"   "mnO2"   "Cl"     "NO3"   
##  [8] "NH4"    "oPO4"   "PO4"    "Chla"   "a1"     "a2"     "a3"    
## [15] "a4"     "a5"     "a6"     "a7"
x <- dist(scale(algaeDataset[, c("mxPH", "mnO2", "Cl","NO3","NH4","oPO4","PO4","Chla")],
center = FALSE))
as.dist(round(as.matrix(x), 2)[1:12, 1:12])
##       1    2    3    4    5    6    7    8    9   10   11
## 2  3.99                                                  
## 3  1.47 3.32                                             
## 4  2.25 3.75 1.36                                        
## 5  1.89 4.26 1.29 1.73                                   
## 6  1.45 4.68 1.51 2.04 0.98                              
## 7  2.18 3.81 1.23 0.63 1.78 1.90                         
## 8  1.91 4.09 0.99 0.95 1.09 1.27 0.76                    
## 9  2.41 4.15 1.62 1.01 2.04 2.25 1.13 1.25               
## 10 2.54 4.30 1.55 1.33 1.98 2.13 1.10 1.11 0.78          
## 11 2.59 4.47 1.67 1.42 2.00 2.11 1.18 1.14 0.86 0.19     
## 12 2.61 4.50 1.67 1.49 2.01 2.09 1.19 1.14 1.01 0.28 0.17
x <- algaeDataset[, c("mxPH", "mnO2", "Cl","NO3","NH4","oPO4","PO4","Chla")]
cm <- colMeans(x)
S <- cov(x)
d <- apply(x, MARGIN = 1, function(x)t(x - cm) %*% solve(S) %*% (x - cm))
d
##          1          2          3          4          5          6 
##   6.308049  19.106097   2.421095   5.180995  10.294317   7.399293 
##          7          8          9         10         11         12 
##   2.041773   1.378710  12.205272   1.197181   1.921584   3.798214 
##         13         14         15         16         17         18 
##   8.532871   2.830503   1.439196   5.165389   2.622491   1.825596 
##         19         20         21         22         23         24 
##   3.608542  58.031899  25.777324   6.083269   1.293435   2.409365 
##         25         26         27         29         30         31 
##   1.691277   1.445833   7.016084   1.342879   6.862262   5.058512 
##         32         33         34         35         36         37 
##   7.307562   1.909092   8.632794  31.685679   4.697365   2.824579 
##         39         40         41         42         43         44 
##   3.936960   3.833429   7.125914   1.908280  13.210620  13.131659 
##         45         46         47         49         50         51 
##   5.733295   5.061218   2.986639   2.483175   5.431851   1.859074 
##         52         53         54         64         65         66 
##   2.127574   1.951258   2.090195   2.905784   6.098314   3.784768 
##         67         68         69         70         71         72 
##   6.337565   8.800744  13.830102  13.513559   4.687019   4.334381 
##         73         74         75         76         77         78 
##   8.476801   4.075346   4.546652  10.461680   1.733699   3.403869 
##         79         80         81         82         83         84 
##   8.807962   2.613294   2.985317   4.259104   4.981331   4.304431 
##         85         86         87         88         89         90 
##   3.437738   3.278232   4.128853  25.149504  39.506861   5.501486 
##         91         92         93         94         95         96 
##  13.788324   4.286977   4.112380   2.979496   4.062759   5.674828 
##         97         98         99        100        101        102 
##  11.629657  22.127963   6.699621   7.079427   5.779818   6.160962 
##        103        104        105        106        107        108 
##   5.127619  10.636963  23.437896  12.990154  19.350300   2.124670 
##        109        110        111        112        113        114 
##   2.776525   1.604639   4.785924   2.079407   3.877778   3.800045 
##        115        117        118        119        120        121 
##   2.172866   4.962100   2.967282   6.686641   6.390291   6.210870 
##        122        123        124        125        126        127 
##   3.344137   5.729451   3.735153   1.605119   3.616362  23.986556 
##        128        129        130        131        132        133 
##  24.607705   4.143984   2.100551   2.340132   4.518660  22.476839 
##        134        135        136        137        138        139 
##  63.942596   8.603364   4.850736   2.216286   2.455642   2.940920 
##        140        141        142        143        144        145 
##   6.700856   4.176732   1.403138   1.257009  11.020921  12.375073 
##        146        147        148        149        150        151 
##  14.543299   1.467437   1.348421   1.598294   4.391603   4.050456 
##        152        153        154        155        156        157 
##   7.058305 161.168546   8.288272   5.881847   8.468986  15.397865 
##        158        159        160        162        163        164 
##   7.938589   1.610956   3.237650  21.289695  21.783274  20.149452 
##        165        166        167        168        169        170 
##   3.879358   4.280981   9.466264   2.935196   6.357279   5.180706 
##        171        172        173        174        175        176 
##   7.223011  16.399980   2.507884   2.278454  16.633284  14.495956 
##        177        178        179        180        181        182 
##   4.928755   2.053170   2.780939   4.186970   2.277912   3.296089 
##        183        185        186        187        188        189 
##   2.185410   1.490406   6.266247   3.768446   1.625527   2.158205 
##        190        191        192        193        194        195 
##   2.233151   4.644156   1.825111   3.490051   2.398118   3.397172 
##        196        197        198        200 
##   3.264242   1.595691   7.517249   2.631665
S
##              mxPH         mnO2         Cl          NO3          NH4
## mxPH    0.2225065   -0.1166057    3.26578   -0.3146066    -147.8650
## mnO2   -0.1166057    5.7944078  -29.82509    1.0997298    -382.7583
## Cl      3.2657796  -29.8250876 2215.30207   38.4726809    6309.3683
## NO3    -0.3146066    1.0997298   38.47268   15.0133862    5704.5208
## NH4  -147.8649973 -382.7582810 6309.36826 5704.5208456 4127337.0433
## oPO4    3.9421181  -87.7889395 1653.33413   47.7364490   41267.4404
## PO4     6.1710802 -144.1914158 2705.30776   78.5551787   52300.3410
## Chla    4.1277801   -6.4007720  136.35243   11.4240425    3754.8089
##              oPO4         PO4        Chla
## mxPH     3.942118     6.17108    4.127780
## mnO2   -87.788939  -144.19142   -6.400772
## Cl    1653.334129  2705.30776  136.352430
## NO3     47.736449    78.55518   11.424043
## NH4  41267.440358 52300.34101 3754.808912
## oPO4  8578.739540 10905.44454  200.672650
## PO4  10905.444542 16668.91384  650.137379
## Chla   200.672650   650.13738  410.655232
cm ##from the column means we can say that mxPH,mnO2,NO3 and Chla are related because the column means are close enough
##       mxPH       mnO2         Cl        NO3        NH4       oPO4 
##   8.078288   9.018587  44.880886   3.384071 537.671598  78.269446 
##        PO4       Chla 
## 146.577647  13.882799

Now let us draw the normal Q-Q plot for all the chemicals observed in the river

For PH level we are having a symmetric distribution with flat tails MNo2 - negatively skewed Cl - positively skewed No3 - positively skewed NH4 - symmetric with flat tails on the right OPo4 - positive skewed Po4 - symmetric with flat tails CHla - negatively skewed with lot of outliers

{qqnorm(algaeDataset[,"mxPH"], main = "PH level") 
  qqline(algaeDataset[,"mxPH"])}

{qqnorm(algaeDataset[,"mnO2"], main = "MnO2 level") 
  qqline(algaeDataset[,"mnO2"])}

{qqnorm(algaeDataset[,"Cl"], main = "Cl level") 
  qqline(algaeDataset[,"Cl"])}

{qqnorm(algaeDataset[,"NO3"], main = "NO3 level") 
  qqline(algaeDataset[,"NO3"])}

{qqnorm(algaeDataset[,"NH4"], main = "NH4 level") 
  qqline(algaeDataset[,"NH4"])}

{qqnorm(algaeDataset[,"oPO4"], main = "oPO4 level") 
  qqline(algaeDataset[,"oPO4"])}

{qqnorm(algaeDataset[,"PO4"], main = "PO4 level") 
  qqline(algaeDataset[,"PO4"])}

{qqnorm(algaeDataset[,"Chla"], main = "Chla level") 
  qqline(algaeDataset[,"Chla"])}

{plot(qchisq((1:nrow(x) - 1/2) / nrow(x), df = 8), sort(d),
     xlab = expression(paste(chi[3]^2, " Quantile")),
     ylab = "Ordered distances")
abline(a = 0, b = 1)} ##symmetric distribution with flat tail on the right

t-test statics are applied on based of the season on 7 different types of algae

Now we will perform t-test statistics for the season and the frequencies of the algae

with(data=algaeDataset,t.test(a1[season=="winter"],a1[season=="spring"],var.equal=TRUE)) ## with this we say that yes there is a lot of algaes 1 blossmings during winter and spring
## 
##  Two Sample t-test
## 
## data:  a1[season == "winter"] and a1[season == "spring"]
## t = 0.97289, df = 103, p-value = 0.3329
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -4.139611 12.111760
## sample estimates:
## mean of x mean of y 
##  16.66316  12.67708
with(data=algaeDataset,t.test(a1[season=="summer"],a1[season=="autumn"],var.equal=TRUE)) ## with this we say that yes there is a lot of algaes 1 blossmings during summer and autumn too
## 
##  Two Sample t-test
## 
## data:  a1[season == "summer"] and a1[season == "autumn"]
## t = -0.30938, df = 77, p-value = 0.7579
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -10.255095   7.496956
## sample estimates:
## mean of x mean of y 
##  15.32093  16.70000
with(data=algaeDataset,t.test(a2[season=="winter"],a2[season=="spring"],var.equal=TRUE)) ##alage 2 also we can see the same amount of blossoms
## 
##  Two Sample t-test
## 
## data:  a2[season == "winter"] and a2[season == "spring"]
## t = 0.1761, df = 103, p-value = 0.8606
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -3.645874  4.356401
## sample estimates:
## mean of x mean of y 
##  7.538596  7.183333
with(data=algaeDataset,t.test(a3[season=="winter"],a3[season=="spring"],var.equal=TRUE)) ## alage 3 also we can see the same amount of blossoms
## 
##  Two Sample t-test
## 
## data:  a3[season == "winter"] and a3[season == "spring"]
## t = -1.5426, df = 103, p-value = 0.126
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -5.8004043  0.7249657
## sample estimates:
## mean of x mean of y 
##  5.078947  7.616667
with(data=algaeDataset,t.test(a4[season=="winter"],a4[season=="spring"],var.equal=TRUE)) ## alage 4 also we can see the same amount of blossoms
## 
##  Two Sample t-test
## 
## data:  a4[season == "winter"] and a4[season == "spring"]
## t = -0.88398, df = 103, p-value = 0.3788
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2.740677  1.050764
## sample estimates:
## mean of x mean of y 
##  1.917544  2.762500
with(data=algaeDataset,t.test(a5[season=="winter"],a5[season=="spring"],var.equal=TRUE)) ## alage 5 also we can see the same amount of blossoms
## 
##  Two Sample t-test
## 
## data:  a5[season == "winter"] and a5[season == "spring"]
## t = 0.82943, df = 103, p-value = 0.4088
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.371902  3.344270
## sample estimates:
## mean of x mean of y 
##  4.640351  3.654167
with(data=algaeDataset,t.test(a6[season=="winter"],a6[season=="spring"],var.equal=TRUE)) ## alage 6 also we can see the same amount of blossoms
## 
##  Two Sample t-test
## 
## data:  a6[season == "winter"] and a6[season == "spring"]
## t = 1.7685, df = 103, p-value = 0.07994
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.3745924  6.5443292
## sample estimates:
## mean of x mean of y 
##  5.447368  2.362500
with(data=algaeDataset,t.test(a7[season=="winter"],a7[season=="spring"],var.equal=TRUE)) ## alage 7 also we can see the same amount of blossoms
## 
##  Two Sample t-test
## 
## data:  a7[season == "winter"] and a7[season == "spring"]
## t = -0.29231, df = 103, p-value = 0.7706
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2.402050  1.784945
## sample estimates:
## mean of x mean of y 
##  2.578947  2.887500

Hotelling T2 test:

For all the algaes all the hotelling test were significant except for algae 6 where we are getting the NA value

library(Hotelling)
## Loading required package: corpcor
t2testalgae <- hotelling.test(mxPH + mnO2 + Cl + NO3 +NH4 + oPO4 + PO4 + Chla ~ a1, data=algaeDataset)
cat("T2 statistic =",t2testalgae$stat[[1]],"\n")
## T2 statistic = 5.56422
print(t2testalgae)
## Test stat:  0.56029 
## Numerator df:  8 
## Denominator df:  29 
## P-value:  0.8011
t2testalgae2 <- hotelling.test(mxPH + mnO2 + Cl + NO3 +NH4 + oPO4 + PO4 + Chla ~ a2, data=algaeDataset)
cat("T2 statistic =",t2testalgae2$stat[[1]],"\n")
## T2 statistic = 7.376566
print(t2testalgae2)
## Test stat:  0.82277 
## Numerator df:  8 
## Denominator df:  58 
## P-value:  0.5859
t2testalgae3 <- hotelling.test(mxPH + mnO2 + Cl + NO3 +NH4 + oPO4 + PO4 + Chla ~ a3, data=algaeDataset)
cat("T2 statistic =",t2testalgae3$stat[[1]],"\n")
## T2 statistic = 3.961561
print(t2testalgae3)
## Test stat:  0.44568 
## Numerator df:  8 
## Denominator df:  63 
## P-value:  0.8888
t2testalgae4 <- hotelling.test(mxPH + mnO2 + Cl + NO3 +NH4 + oPO4 + PO4 + Chla ~ a4, data=algaeDataset)
cat("T2 statistic =",t2testalgae4$stat[[1]],"\n")
## T2 statistic = 12.07326
print(t2testalgae4)
## Test stat:  1.4066 
## Numerator df:  8 
## Denominator df:  96 
## P-value:  0.2036
t2testalgae5 <- hotelling.test(mxPH + mnO2 + Cl + NO3 +NH4 + oPO4 + PO4 + Chla ~ a5, data=algaeDataset)
cat("T2 statistic =",t2testalgae5$stat[[1]],"\n")
## T2 statistic = 18.55548
print(t2testalgae5)
## Test stat:  2.0697 
## Numerator df:  8 
## Denominator df:  58 
## P-value:  0.0537
t2testalgae6 <- hotelling.test(mxPH + mnO2 + Cl + NO3 +NH4 + oPO4 + PO4 + Chla ~ a6, data=algaeDataset)
cat("T2 statistic =",t2testalgae6$stat[[1]],"\n")
## T2 statistic = NA
print(t2testalgae6)
## Test stat:  NA 
## Numerator df:  8 
## Denominator df:  86 
## P-value:  NA
t2testalgae7 <- hotelling.test(mxPH + mnO2 + Cl + NO3 +NH4 + oPO4 + PO4 + Chla ~ a7, data=algaeDataset)
cat("T2 statistic =",t2testalgae7$stat[[1]],"\n")
## T2 statistic = 15.27807
print(t2testalgae7)
## Test stat:  1.7629 
## Numerator df:  8 
## Denominator df:  84 
## P-value:  0.09601

Principal Component Analysis:

dim(algaeDataset)
## [1] 184  18
numericAlgaeData <- algaeDataset[,-c(1,2,3,12,13,14,15,16,17,18)]
cor(numericAlgaeData)
##             mxPH        mnO2          Cl        NO3         NH4
## mxPH  1.00000000 -0.10269374  0.14709539 -0.1721302 -0.15429757
## mnO2 -0.10269374  1.00000000 -0.26324536  0.1179077 -0.07826816
## Cl    0.14709539 -0.26324536  1.00000000  0.2109583  0.06598336
## NO3  -0.17213024  0.11790769  0.21095831  1.0000000  0.72467766
## NH4  -0.15429757 -0.07826816  0.06598336  0.7246777  1.00000000
## oPO4  0.09022909 -0.39375269  0.37925596  0.1330145  0.21931121
## PO4   0.10132957 -0.46396073  0.44519118  0.1570297  0.19939575
## Chla  0.43182377 -0.13121671  0.14295776  0.1454929  0.09120406
##             oPO4        PO4        Chla
## mxPH  0.09022909  0.1013296  0.43182377
## mnO2 -0.39375269 -0.4639607 -0.13121671
## Cl    0.37925596  0.4451912  0.14295776
## NO3   0.13301452  0.1570297  0.14549290
## NH4   0.21931121  0.1993958  0.09120406
## oPO4  1.00000000  0.9119646  0.10691478
## PO4   0.91196460  1.0000000  0.24849223
## Chla  0.10691478  0.2484922  1.00000000
algae_pca <- prcomp(numericAlgaeData,scale = TRUE)
algae_pca
## Standard deviations (1, .., p=8):
## [1] 1.6534534 1.3228050 1.1314561 0.8800021 0.8182890 0.7177949 0.4570020
## [8] 0.2607780
## 
## Rotation (n x k) = (8 x 8):
##             PC1         PC2          PC3         PC4          PC5
## mxPH  0.1229044 -0.41654322  0.561511592  0.04183663 -0.077012393
## mnO2 -0.3406130  0.24345520  0.224488272  0.45242066 -0.717115848
## Cl    0.3710606 -0.06688890 -0.004180915  0.80702475  0.381375926
## NO3   0.2234969  0.61831159  0.247678574  0.12982214  0.044840756
## NH4   0.2521532  0.58568950  0.147954838 -0.27347425  0.123589856
## oPO4  0.5157449 -0.07397518 -0.261019584 -0.05962805 -0.455432104
## PO4   0.5469393 -0.10037673 -0.187249761 -0.05833390 -0.331087209
## Chla  0.2291809 -0.14784435  0.669225868 -0.20898804 -0.006638359
##              PC6         PC7         PC8
## mxPH  0.68712332 -0.11191985  0.06119847
## mnO2 -0.05369360  0.21785668  0.07094528
## Cl   -0.06828080  0.23437668 -0.03861628
## NO3   0.02110287 -0.69577863 -0.05456656
## NH4   0.31297699  0.61468449  0.07511114
## oPO4  0.09139452  0.02136500 -0.66379242
## PO4  -0.11552993 -0.07266973  0.72392668
## Chla -0.63262645  0.13190038 -0.12814403
summary(algae_pca)
## Importance of components:
##                           PC1    PC2    PC3    PC4    PC5    PC6     PC7
## Standard deviation     1.6535 1.3228 1.1315 0.8800 0.8183 0.7178 0.45700
## Proportion of Variance 0.3417 0.2187 0.1600 0.0968 0.0837 0.0644 0.02611
## Cumulative Proportion  0.3417 0.5605 0.7205 0.8173 0.9010 0.9654 0.99150
##                           PC8
## Standard deviation     0.2608
## Proportion of Variance 0.0085
## Cumulative Proportion  1.0000
plot(algae_pca)

algaeDataset$a1Cat[algaeDataset$a1<=4.85] = "Less" 
algaeDataset$a1Cat[algaeDataset$a1>4.85] = "More"
algaeDataset$a2Cat[algaeDataset$a2<=3.6] = "Less" 
algaeDataset$a2Cat[algaeDataset$a2>3.6] = "More"
algaeDataset$a3Cat[algaeDataset$a3<=1.70] = "Less" 
algaeDataset$a3Cat[algaeDataset$a3>1.70] = "More"
algaeDataset$a4Cat[algaeDataset$a4<=1.846] = "Less" 
algaeDataset$a4Cat[algaeDataset$a4>1.846] = "More"
algaeDataset$a5Cat[algaeDataset$a5<=2.650] = "Less" 
algaeDataset$a5Cat[algaeDataset$a5>2.650] = "More"
algaeDataset$a6Cat[algaeDataset$a6<=6.447] = "Less" 
algaeDataset$a6Cat[algaeDataset$a6>6.447] = "More"
algaeDataset$a7Cat[algaeDataset$a7<=1.00] = "Less" 
algaeDataset$a7Cat[algaeDataset$a7>1.00] = "More"

Let us find out eigen values:

eigen_algaes <- algae_pca$sdev^2
eigen_algaes
## [1] 2.73390819 1.74981296 1.28019290 0.77440364 0.66959688 0.51522950
## [7] 0.20885079 0.06800514
names(eigen_algaes) <- paste("PC",1:8,sep="")
eigen_algaes
##        PC1        PC2        PC3        PC4        PC5        PC6 
## 2.73390819 1.74981296 1.28019290 0.77440364 0.66959688 0.51522950 
##        PC7        PC8 
## 0.20885079 0.06800514
sumlambdas_algaes <- sum(eigen_algaes)
sumlambdas_algaes
## [1] 8
propvar_algaes <- eigen_algaes/sumlambdas_algaes
propvar_algaes
##         PC1         PC2         PC3         PC4         PC5         PC6 
## 0.341738523 0.218726620 0.160024113 0.096800454 0.083699610 0.064403688 
##         PC7         PC8 
## 0.026106349 0.008500642
cumvar_algaes <- cumsum(propvar_algaes)
cumvar_algaes
##       PC1       PC2       PC3       PC4       PC5       PC6       PC7 
## 0.3417385 0.5604651 0.7204893 0.8172897 0.9009893 0.9653930 0.9914994 
##       PC8 
## 1.0000000
matlambdas_algaes <- rbind(eigen_algaes,propvar_algaes,cumvar_algaes)
matlambdas_algaes
##                      PC1       PC2       PC3        PC4        PC5
## eigen_algaes   2.7339082 1.7498130 1.2801929 0.77440364 0.66959688
## propvar_algaes 0.3417385 0.2187266 0.1600241 0.09680045 0.08369961
## cumvar_algaes  0.3417385 0.5604651 0.7204893 0.81728971 0.90098932
##                       PC6        PC7         PC8
## eigen_algaes   0.51522950 0.20885079 0.068005139
## propvar_algaes 0.06440369 0.02610635 0.008500642
## cumvar_algaes  0.96539301 0.99149936 1.000000000
rownames(matlambdas_algaes) <- c("Eigenvalues","Prop. variance","Cum. prop. variance")
round(matlambdas_algaes,4)
##                        PC1    PC2    PC3    PC4    PC5    PC6    PC7
## Eigenvalues         2.7339 1.7498 1.2802 0.7744 0.6696 0.5152 0.2089
## Prop. variance      0.3417 0.2187 0.1600 0.0968 0.0837 0.0644 0.0261
## Cum. prop. variance 0.3417 0.5605 0.7205 0.8173 0.9010 0.9654 0.9915
##                        PC8
## Eigenvalues         0.0680
## Prop. variance      0.0085
## Cum. prop. variance 1.0000
attach(algaeDataset)
algae_pca$rotation
##             PC1         PC2          PC3         PC4          PC5
## mxPH  0.1229044 -0.41654322  0.561511592  0.04183663 -0.077012393
## mnO2 -0.3406130  0.24345520  0.224488272  0.45242066 -0.717115848
## Cl    0.3710606 -0.06688890 -0.004180915  0.80702475  0.381375926
## NO3   0.2234969  0.61831159  0.247678574  0.12982214  0.044840756
## NH4   0.2521532  0.58568950  0.147954838 -0.27347425  0.123589856
## oPO4  0.5157449 -0.07397518 -0.261019584 -0.05962805 -0.455432104
## PO4   0.5469393 -0.10037673 -0.187249761 -0.05833390 -0.331087209
## Chla  0.2291809 -0.14784435  0.669225868 -0.20898804 -0.006638359
##              PC6         PC7         PC8
## mxPH  0.68712332 -0.11191985  0.06119847
## mnO2 -0.05369360  0.21785668  0.07094528
## Cl   -0.06828080  0.23437668 -0.03861628
## NO3   0.02110287 -0.69577863 -0.05456656
## NH4   0.31297699  0.61468449  0.07511114
## oPO4  0.09139452  0.02136500 -0.66379242
## PO4  -0.11552993 -0.07266973  0.72392668
## Chla -0.63262645  0.13190038 -0.12814403
print(algae_pca)
## Standard deviations (1, .., p=8):
## [1] 1.6534534 1.3228050 1.1314561 0.8800021 0.8182890 0.7177949 0.4570020
## [8] 0.2607780
## 
## Rotation (n x k) = (8 x 8):
##             PC1         PC2          PC3         PC4          PC5
## mxPH  0.1229044 -0.41654322  0.561511592  0.04183663 -0.077012393
## mnO2 -0.3406130  0.24345520  0.224488272  0.45242066 -0.717115848
## Cl    0.3710606 -0.06688890 -0.004180915  0.80702475  0.381375926
## NO3   0.2234969  0.61831159  0.247678574  0.12982214  0.044840756
## NH4   0.2521532  0.58568950  0.147954838 -0.27347425  0.123589856
## oPO4  0.5157449 -0.07397518 -0.261019584 -0.05962805 -0.455432104
## PO4   0.5469393 -0.10037673 -0.187249761 -0.05833390 -0.331087209
## Chla  0.2291809 -0.14784435  0.669225868 -0.20898804 -0.006638359
##              PC6         PC7         PC8
## mxPH  0.68712332 -0.11191985  0.06119847
## mnO2 -0.05369360  0.21785668  0.07094528
## Cl   -0.06828080  0.23437668 -0.03861628
## NO3   0.02110287 -0.69577863 -0.05456656
## NH4   0.31297699  0.61468449  0.07511114
## oPO4  0.09139452  0.02136500 -0.66379242
## PO4  -0.11552993 -0.07266973  0.72392668
## Chla -0.63262645  0.13190038 -0.12814403
algaetyp_pca <- cbind(data.frame(a1Cat),algae_pca$x)
algaetyp_pca
##     a1Cat          PC1         PC2          PC3         PC4          PC5
## 1    Less  0.820687351  0.28952661  1.247077898  0.10280148 -0.258871961
## 2    Less  3.730027226 -1.25263632 -1.919915169 -0.27643930 -2.447314074
## 3    Less  0.173728419  0.40219049  0.223270034  0.39055864 -1.078906577
## 4    Less  0.464201113 -0.65403533 -0.860002099 -0.07044543  1.590370250
## 5    More  0.090824457  1.11267251  0.418767667  0.52084488  0.381573327
## 6    More -0.594295147  1.14812498  1.729132129  1.28066393 -0.492580725
## 7    Less -0.461845357 -0.27379594 -0.201312021  0.86610489 -0.034500048
## 8    More -0.626870183  0.45685288  0.155396725  0.76133867 -0.008336383
## 9    More -0.070006256 -1.45557256 -0.020718879 -1.27202952  1.734070270
## 10   More -1.490732163  0.01488890 -0.400514057 -0.26213845 -0.081104340
## 11   More -1.773498154  0.30642031 -0.558065117 -0.20267156  0.007206828
## 12   More -2.063592422  0.69122272 -0.710360856  0.07556950 -0.377940602
## 13   More -1.284076861 -0.12195696  0.749976035 -0.78668971  0.152078804
## 14   More -2.022716140  0.44405111 -0.400251269  0.07418711 -0.489111165
## 15   More -1.508616028  0.04241445 -0.455218138 -0.40285710  0.007547931
## 16   More -1.750959363  0.48439613 -0.707361393 -0.06688095 -0.542181230
## 17   More -1.859573702  0.37619460 -0.349979959  0.10016219 -0.654858803
## 18   More -1.558924415  0.30456846 -0.794496754 -0.32440504  0.001968922
## 19   More -1.553736415  0.62088190 -1.081874966 -0.24748378 -0.245324287
## 20   Less  7.138933614  1.11883370 -2.910237166 -2.41808400 -1.560931436
## 21   Less  4.321121136  0.23346476 -1.628006760  0.45028750 -3.063291345
## 22   More -1.861881449  0.53500147 -1.312069945 -0.59356919  0.314918126
## 23   More -1.317455922  0.40148368 -0.212008845  0.21158529  0.121220049
## 24   More -1.504799434  0.27945011 -0.739151499 -0.48786985  0.601922799
## 25   More -1.688033251  0.10219781 -0.404020313 -0.28571424  0.317468724
## 26   Less -1.541335712  0.65894025 -0.219973765  0.02152859 -0.128086971
## 27   More -1.737037580  0.68325415 -1.423821602 -0.53961478  0.725662967
## 29   More -1.445319496 -0.16739228 -0.362534668 -0.16005154  0.005556208
## 30   More -2.129119162  0.68333377 -1.131755757 -0.07546667 -0.231507386
## 31   Less -1.138986912  0.92414223 -0.790507510  0.20875880 -1.168907985
## 32   More  1.114558776 -0.11276569 -0.929457075 -0.06821939 -1.787575174
## 33   Less -0.971587476  0.40434746 -0.347890921  0.13920528 -0.701575197
## 34   More -0.663148571  0.79627656  0.572846593 -0.20159175  0.321024056
## 35   More -0.430903114  1.13516793  0.279977741 -1.14638993  1.192347941
## 36   More -0.187621137 -0.01155591  0.545059307 -0.34711322  0.315239228
## 37   More -1.960674027 -0.24455929  0.208120214 -0.13908162 -0.263869000
## 39   Less  0.939939183 -0.42364707 -0.305415151 -0.48420743 -1.070843115
## 40   Less  0.597687584  0.03709817 -0.430071193 -0.10107442 -1.431117519
## 41   Less  1.717866799 -0.11335242 -1.018455972  0.02454441  0.625782296
## 42   Less  0.410827844 -0.17001855 -0.068685335 -0.18819564  0.666982561
## 43   Less  2.500527310 -0.01215446 -0.091926493 -0.20388085 -0.998603006
## 44   Less  2.204181663  0.05437041 -0.397058522  0.16357712 -1.312247104
## 45   More -1.276339429  0.37605049  0.844101120  1.57974096 -0.562597024
## 46   More -0.922866667  0.38335662  0.586808873  1.70402881 -0.226304823
## 47   More -1.233487853  0.61905826  0.128981677  1.26876546 -0.162316227
## 49   More -1.044407738  0.46374216 -0.756408757 -0.23183829 -0.050409174
## 50   More -1.726254795  0.92417537 -0.480807899  0.05113386 -0.134157800
## 51   Less -1.213435785  0.81114472 -0.283245017  0.19584731  0.189703855
## 52   More -1.189658195 -0.22102299 -0.274303607 -0.31094607  0.821181240
## 53   More -1.939066120  0.16888167 -0.250982622 -0.06710562 -0.235296021
## 54   More -1.665897539 -0.07272219 -0.446695022 -0.47307558  0.344887705
## 64   More -2.054129845  0.45478573 -0.619630151 -0.16062891 -0.092760343
## 65   More -2.253602251  0.96752710 -0.986227813 -0.03151039 -0.293043131
## 66   More -2.039839003  0.43245399 -0.878346158 -0.33980835  0.123258613
## 67   More -2.022885433  0.67347035 -1.197598498 -0.43349745  0.253757140
## 68   More -2.423826500  1.09630468 -1.187073416  0.01736963 -0.387226394
## 69   Less  2.396058237 -0.62529207 -2.311200714 -2.01946494  1.031175124
## 70   Less  2.103452475 -0.26574628 -2.435357007 -1.98050566  1.118372307
## 71   More  1.166055264  0.11804099 -0.920102542 -0.97069899 -0.100851747
## 72   More -0.084405646 -0.38604405  0.222612389 -0.08501933  0.288110480
## 73   Less -0.545247770  1.15923158  0.379295588  0.34932510 -0.034235934
## 74   Less  1.679706914 -0.44138892 -0.147335376  1.28796552  0.441990295
## 75   Less  1.454019074 -0.61810400 -0.309737593  1.03200075  0.979245884
## 76   Less  0.563207609 -0.80437748  1.357447454  0.05130933 -0.578323452
## 77   More -0.985444107 -0.19144233 -0.182549613  0.01721149 -0.026355390
## 78   More -0.451382035 -0.61572372 -0.762262786 -0.76927453  1.061126131
## 79   More -0.057493028 -0.88650776 -1.019382662 -1.27915210  1.810277821
## 80   More -1.095362279  0.60251012 -0.918970515 -0.36136616  0.095532396
## 81   More -1.333419609  0.80902589 -0.912305891 -0.27255717  0.013280173
## 82   Less -1.666303670  1.32774351 -0.604966779  0.13177256 -0.401139186
## 83   More -0.721719240  0.86210906 -0.274927183 -0.51737237  0.246078010
## 84   More -1.337396983  1.35655572 -0.571814453  0.11279506 -0.362639860
## 85   Less -0.083256508  0.93292798 -0.994443739  0.11449513 -0.856226549
## 86   Less  1.113020956  0.20839951 -1.442137565 -0.49765490  0.504473199
## 87   Less -0.627041622  0.88931399 -0.956174214  0.26053208 -0.435938616
## 88   Less  5.109797276  0.73973250 -2.342805969 -1.98094426 -0.806423253
## 89   Less  3.581271226  1.61851580 -1.509671936 -0.39707768 -2.025972681
## 90   Less  2.402067939 -0.99370001  0.749068559  0.99448125 -0.309143639
## 91   Less  3.042285366 -1.09613072 -0.504255215  2.26730749 -0.755262912
## 92   Less  1.246390505  0.04440299 -0.475083245  1.20411612 -0.971532136
## 93   Less  1.168284761 -0.77565430  1.210789026 -0.01329431 -0.335906293
## 94   Less  0.534300461 -0.01010609 -0.777160489  0.67564889 -0.804692423
## 95   Less  0.418246779  0.47850635 -0.460533973  0.92400860 -1.235081620
## 96   More -0.485970670 -0.81981847  0.817299198  0.42738472 -0.178995237
## 97   Less  1.873365557 -2.42670320  2.377118266 -1.01989963  0.596517542
## 98   Less  2.171759680 -2.51278222  2.950457655 -1.53709532  0.906876220
## 99   Less  0.743301691 -0.15264300 -0.864507879  0.63487946  1.266562174
## 100  More  0.620426701  0.44884728  0.062924444  0.55428841  0.709115650
## 101  More  0.330043641 -0.15424273 -0.062471765 -0.17733798  0.893576720
## 102  More  0.062065662 -0.16969621 -0.756282343  0.28572965  1.373754735
## 103  More  0.583611920 -0.22787570 -0.709759736 -0.40908956  1.356880437
## 104  More  0.961347019  1.32445648 -0.999963449  0.31555502 -0.156594157
## 105  More  0.924877797  0.25710430  1.565810776 -0.34402721 -0.347680994
## 106  More  0.102539738 -0.95199032  0.195819990 -0.04613245  0.486992618
## 107  More  0.893910241  0.85421591  1.658577038  0.04134692 -0.722587146
## 108  More -0.462914504  0.39204247  0.686187798  0.38621562 -0.394128181
## 109  Less  0.472041799 -0.73299688  0.528640497 -0.76721331  0.900963026
## 110  Less -0.337791385  0.51190216  0.512384107  0.26564082 -0.643848965
## 111  More -1.498297912 -0.60079892  0.618051527 -0.22763026 -0.028263229
## 112  More -1.802502017  0.03828850  0.155759881  0.05356390 -0.386534295
## 113  More -1.783162847 -0.15500168  0.630342193  0.13924399 -0.557736446
## 114  Less -0.358145368 -0.51271408 -1.077150953 -0.31302484  1.269402695
## 115  More -0.828182432 -0.28038142 -0.397626764  0.45431446  0.220844403
## 117  More -1.833557350 -0.51270813  0.589300195 -0.01110539 -0.641268448
## 118  More -1.937213785 -0.21738427  0.349626478  0.03456519 -0.471667866
## 119  Less  3.182807746 -1.18676557 -0.530592652 -0.44889821 -0.361445212
## 120  Less  2.593888375 -0.68644148 -1.006134281  1.01818389  0.154058292
## 121  Less  1.092425151  0.35077618 -0.110998005  0.17826168 -0.779908089
## 122  Less  1.319525062 -0.26362356 -0.387845066 -0.41925237 -0.193745160
## 123  Less  0.981747784  0.28900430 -0.443339059  0.19995658 -0.653311104
## 124  More -1.219868806  0.62831948 -0.875258977 -0.17897218 -0.425385259
## 125  Less -0.725132657 -0.35616208 -0.007866780 -0.31756837 -0.428326564
## 126  Less -0.950094292 -0.42794209  0.410308309 -0.01683774 -0.669086036
## 127  Less  1.148682378 -1.06272515  3.868961232 -0.37809053 -1.307801327
## 128  Less  2.107548021 -2.03165410  3.771833103 -1.62304786 -0.171711639
## 129  Less  0.297479224 -0.43381555  1.508818718 -0.36613620 -0.550400467
## 130  Less -1.052942550 -0.51630224  0.590837531 -0.27934429 -0.303725317
## 131  Less -0.780133616 -0.59131317 -0.242412756 -0.66862957  0.336978483
## 132  Less -1.472956115  0.59893788 -1.096394307 -0.21313538 -0.284486748
## 133  Less  1.391890582  1.37986781  0.423796337  2.42000161  1.426695912
## 134  Less  4.076414300 -0.17566595 -0.942395685  5.85120866  2.172889797
## 135  More -0.001571725  0.76346167  0.134864415  2.28445355  0.044877500
## 136  More  0.693303822  0.15916102 -0.806999053  0.05452838 -0.798327812
## 137  Less -0.944460716  0.55370758  0.143369648  0.63487674 -0.590168352
## 138  More -0.702692311 -0.66152476  0.410572587  0.10823461 -0.127020471
## 139  More -0.292279487 -0.71203382 -0.711413733 -0.50611525  0.949203047
## 140  Less -0.118406575  1.45335424  0.152734193  0.79387559 -0.445169419
## 141  Less  0.939080291 -0.17202292 -0.627636517 -0.29527577  0.490542870
## 142  More -1.550208789  0.15736608 -0.520054220 -0.32830271  0.147223443
## 143  More -1.674792127  0.30376197 -0.192709460 -0.09178828 -0.077962200
## 144  Less  1.502675930  0.49201120 -0.004135168 -0.20952333  1.625328065
## 145  Less  0.747312382  1.08672547 -0.804845340  0.44193536  1.240817490
## 146  More  1.178401834  1.04370285 -0.475602931 -0.19723426  0.911488102
## 147  More -0.108266124 -0.70956873  0.599128948 -0.37864511  0.385688498
## 148  More -0.682681571 -0.45539990  0.765961553  0.04464203  0.022731065
## 149  More -0.387030827 -0.58897790  0.261465412  0.17242454  0.138507214
## 150  Less  1.018009135 -1.47610751  0.234817991 -0.97026428  0.866556576
## 151  Less -0.659354777 -0.78549321  1.530366185  0.37438475 -0.412233605
## 152  Less  0.084501862 -0.39210678 -0.711024070 -0.71013086  1.816715474
## 153  Less  4.532049054 14.32540477  5.303035226 -1.64016350  1.657671115
## 154  Less  0.235692820 -0.30104499 -0.716571703  1.05011463  2.004048710
## 155  Less -0.256625901  0.64020389  0.661049022  1.22782900  0.557428468
## 156  More  2.916449864 -0.34974299 -0.838122754 -0.61598249  1.197027546
## 157  More  2.130700135  0.03837477 -1.152020789 -0.75158213  0.561862991
## 158  Less  0.642893835 -1.67117559  0.418402654 -1.03908076  1.679079935
## 159  Less -1.129784345 -0.42242693  0.907192758 -0.10359892 -0.262299001
## 160  Less -0.918932737 -0.35548189  1.291995235  0.02311793 -0.565327232
## 162  More  2.353274784 -2.94920231  3.420526920 -1.48793359  0.030585864
## 163  More  1.945165085 -2.05350090  2.733964364 -0.99391716 -0.976994772
## 164  Less -0.618524420 -1.18261165  3.647178495  0.13901906 -0.776877205
## 165  Less -1.275888269  1.10627010 -0.905536604 -0.10045161  0.095106152
## 166  Less -0.584243754  1.10229877 -0.877411181  0.07371001 -0.562772583
## 167  Less  1.995699313 -2.33335747  1.726170821 -0.64777787  1.139946228
## 168  Less -0.049775043 -0.62677063  0.827110334  0.65363512 -0.614424933
## 169  More  1.448096292 -0.51768836  0.071277302 -0.17065506 -0.940156748
## 170  Less  1.010937356 -0.07804698 -0.781651952 -0.27739762 -0.634350268
## 171  Less  2.430073914 -0.57260265 -0.433708192  0.02491070  0.190600932
## 172  Less  3.712418313 -0.38321604 -1.794582123  1.04311751 -0.160836183
## 173  Less  0.464709592 -0.16794450 -0.134201587  1.23861137  0.289836615
## 174  Less  0.288264865 -0.80815942  0.152630037  0.26334806  0.711916445
## 175  Less  1.627966953 -0.60390431  1.157094172  3.05941994  0.589218406
## 176  Less  2.538557432 -1.65668036  0.761939460  1.93219538  1.166398379
## 177  More -1.619529803 -0.61666512  0.642560937 -0.10581612 -0.356599227
## 178  More -1.849843018 -0.06543619 -0.060862670 -0.15991163 -0.224947833
## 179  More -1.706948653 -0.36521502  0.275844002 -0.18549443 -0.118342389
## 180  More -1.728060965 -0.61631293  0.511793686 -0.26296819 -0.086344704
## 181  More -1.752124512 -0.31897537 -0.036809749 -0.40409097  0.157837547
## 182  More -1.762636719 -0.49430472  0.522054645 -0.21107778 -0.189329458
## 183  More -1.692748425 -0.34617629  0.190330612 -0.29633518 -0.027033366
## 185  More -1.491808954 -0.22004337 -0.180072452 -0.23886639 -0.221151938
## 186  Less  0.839501990 -0.33522787  1.930893979  0.05078490 -1.019334849
## 187  Less -0.852262903 -0.26397496  1.295819266  0.26208640 -0.767484576
## 188  Less -0.458499580 -0.50954642  0.427743048 -0.41398657  0.264963069
## 189  Less -0.727049151 -0.32588686  1.003057318  0.07591429 -0.607220352
## 190  Less -0.208859019 -0.90203717  0.696134011 -0.84390815  0.225864224
## 191  More -1.134051552 -0.41530241  0.810063363  0.16538221 -0.702743225
## 192  Less -1.347736567 -0.35827330  0.485644698 -0.11243687 -0.272879738
## 193  Less -0.885300638 -0.52976836 -0.202438563 -0.65919568  0.221423609
## 194  Less -0.658302683 -0.30048567  1.228998039  0.09462446 -0.625366137
## 195  More -0.865656658 -0.52419201  0.352810976 -0.54025837  0.477228930
## 196  More -0.626832428 -0.21092010  0.108468626 -0.31808793  0.182800955
## 197  More -1.111432040  0.01581517  0.291477332 -0.00316459 -0.386780238
## 198  Less  1.159800412 -0.77464689  0.486146403  1.13152911  1.328521400
## 200  Less  0.585070923 -0.91737958  0.402755888  0.26822661  0.975991531
##              PC6           PC7           PC8
## 1   -1.254907054 -1.036429e-01 -0.3275141504
## 2    0.732427362  3.804146e-05 -0.1031313881
## 3   -0.076327992 -2.217242e-01 -0.0810449028
## 4    0.341182442 -2.375011e-01  0.0041561220
## 5    0.079724465 -1.298963e+00 -0.2314477640
## 6   -0.287807382 -5.217429e-01 -0.1269138264
## 7    0.306636141  3.890078e-01  0.0282665027
## 8    0.107243324 -1.826340e-01 -0.1063137117
## 9    1.270158158 -4.746347e-01 -0.1172808967
## 10   0.172578749  8.779985e-02 -0.0668006746
## 11  -0.157149568  1.608981e-01 -0.1301719675
## 12  -0.550176227  3.467045e-01 -0.1135584874
## 13  -1.334280508  4.020799e-01 -0.4055698773
## 14  -0.145922531  3.006561e-01 -0.1323610380
## 15   0.137488919  2.969272e-02  0.1146390613
## 16  -0.489141813  2.891875e-01  0.3876250674
## 17  -0.107632482  3.097730e-01  0.0557631250
## 18  -0.290372830  1.373047e-01  0.0072268528
## 19  -0.672826443  2.147590e-01 -0.1480937507
## 20   1.161968527  1.930351e+00  0.1665028467
## 21  -0.345585384  3.837402e-01 -0.3332761717
## 22  -0.833763375  3.303265e-01 -0.2378939443
## 23  -0.338147073  6.844367e-02 -0.1187097917
## 24  -0.255335538  6.783754e-02 -0.0875373681
## 25   0.035627564  7.791411e-02 -0.1245404079
## 26  -0.147195376 -2.161710e-01  0.0008930389
## 27  -1.000834126  1.490909e-01 -0.2402955686
## 29   0.263962334  2.254023e-01 -0.0574232663
## 30  -0.893184295  6.456065e-01 -0.1440778057
## 31  -0.814997769  1.251057e-01  0.0999310951
## 32   0.329631468 -3.208749e-01 -0.2164692745
## 33  -0.255919117  1.716256e-02  0.1820218302
## 34   1.312823035  9.214440e-01  0.1267816733
## 35   1.660109355  2.107273e+00  0.1625983252
## 36   1.451347514  1.028163e-01 -0.0253343621
## 37   0.729230853  1.911761e-01 -0.0312418505
## 39   0.383485172 -3.258795e-01 -0.2068493965
## 40   0.139057093 -2.848163e-01 -0.0636953072
## 41   0.117468464 -8.877048e-01  0.2394887647
## 42   0.130356195 -2.157562e-01  0.2418854623
## 43   0.039870344 -1.224840e+00 -0.3857006970
## 44   0.362110465 -1.040699e+00 -0.4652684827
## 45   0.603197162  6.133331e-02  0.0740237004
## 46   0.484955277  2.682411e-02 -0.0867741371
## 47   0.158839713  7.595163e-03 -0.0457629723
## 49  -0.426700450 -1.374626e-01  0.2604255624
## 50  -1.133163248  1.986987e-01 -0.2557299821
## 51  -0.542728240 -1.478238e-01 -0.0833723344
## 52   0.182163210 -2.127183e-02 -0.1485965826
## 53   0.129008583  2.414191e-01 -0.0867157647
## 54   0.167699580  1.098680e-01 -0.1514266303
## 64  -0.360107232  2.956661e-01 -0.1244846608
## 65  -0.889526818  4.527730e-01 -0.1426070200
## 66  -0.523262826  3.266177e-01 -0.1518943950
## 67  -1.016884174  3.545495e-01 -0.1868790112
## 68  -1.199822067  5.361717e-01 -0.1786640136
## 69  -0.460904065 -1.416675e-02 -0.0672963441
## 70  -0.051545351  1.476308e-01 -0.1104692654
## 71  -0.124902621  5.599780e-01  0.2268565708
## 72   0.832040799 -4.625342e-01  0.3406702659
## 73  -0.141921338 -1.033940e+00 -0.3842066387
## 74  -0.375336957  2.082403e-01 -0.0029130604
## 75   0.034012413  7.303707e-02  0.2094190562
## 76   1.230291098 -7.337531e-01  0.4138074088
## 77   0.285013991  2.164527e-01  0.2539209886
## 78   0.238797316 -5.486445e-02  0.0773366189
## 79   0.298436097 -2.729065e-01  0.0252916542
## 80  -0.488600692 -2.060131e-01  0.1765749823
## 81  -0.588265214 -3.166961e-02 -0.1912985994
## 82  -0.887833220 -1.745168e-01  0.0281804380
## 83  -1.226518905 -4.423500e-01 -0.0311395237
## 84  -0.682753342 -4.841471e-01 -0.0837758811
## 85  -0.510540493  4.078020e-03  0.1929673188
## 86  -0.320235349 -1.777436e-01  0.0923933802
## 87  -0.736378633  9.459540e-02  0.3032354623
## 88   0.731352949  8.074608e-01  0.2333123015
## 89  -0.164143405  3.396104e-01  1.2934217137
## 90  -0.392645851  1.775039e-01 -0.1877696651
## 91   0.934296228  2.466780e-01  0.0533811673
## 92   0.081461034 -4.216018e-02 -0.1272306065
## 93   0.422305876 -5.507839e-01  0.1032443598
## 94  -0.416894646  2.899443e-01  0.0852409918
## 95  -0.155305287 -8.334673e-02 -0.1281615676
## 96   0.233693056  5.809688e-01  0.4266526380
## 97  -0.424093371  2.675838e-01  0.0016848314
## 98  -1.509245391  4.111979e-01 -0.1815478204
## 99  -0.045929581 -2.595798e-01  0.4251127693
## 100 -0.804119065 -3.394208e-01  0.5127511323
## 101 -1.188590620 -1.350729e-03  0.3448048111
## 102 -0.257290802 -9.569788e-03  0.4239992132
## 103 -0.689613758 -1.137877e-01  0.2068435850
## 104 -0.559132952 -8.481183e-01  0.5407136652
## 105 -2.821062479  9.495555e-02  0.6031382872
## 106  1.092212254 -3.531988e-01  0.7896381488
## 107 -2.374251082 -5.064052e-01  0.4907513739
## 108  0.354851559  6.620927e-03  0.2503257925
## 109  0.251246494 -1.246063e-01  0.0055233242
## 110  0.062615025 -3.191079e-01  0.0134918497
## 111  1.309873286 -1.128868e-01 -0.0078261452
## 112  0.554908370  6.898068e-02  0.0403497925
## 113  0.961419785  1.440636e-01  0.0227996411
## 114 -0.035923082  1.807324e-01  0.0177898104
## 115  0.139076733  5.260945e-01  0.0591316413
## 117  1.113804566  2.455637e-01  0.0022992057
## 118  0.605664713  2.978337e-01  0.0104779826
## 119  0.028843446 -5.270954e-01  0.1072713916
## 120  0.264832291 -2.031879e-01 -0.2810193777
## 121  0.223465495 -8.248062e-01  0.3075288939
## 122 -0.107448286 -6.631532e-01 -0.0971992949
## 123  0.247921314 -7.650413e-01 -0.3262196395
## 124 -0.799579750  2.068535e-01  0.2035880208
## 125  0.547718199 -9.124416e-02  0.1461069331
## 126  1.089593447 -1.256524e-01  0.0091673710
## 127 -1.052509684 -7.218260e-02  0.6520456853
## 128 -1.767568873  5.449313e-03  0.0097528659
## 129 -0.907385262 -1.180946e-02  0.0103275539
## 130  0.691534462  1.187478e-01  0.0493232893
## 131  0.723260683 -1.347000e-01 -0.0393252102
## 132 -0.824725674  3.458857e-01 -0.1859735885
## 133 -0.149381975  1.164845e+00  0.4806626381
## 134 -0.553650149  1.049144e+00 -0.0423145869
## 135  0.007468407  9.863990e-03 -0.3208140555
## 136  0.252951952 -4.753443e-01 -0.3678737745
## 137  0.297473344 -3.186678e-01  0.0027598934
## 138  0.476808917  2.872626e-01  0.2630721129
## 139  0.419092941  1.446609e-02 -0.1184623885
## 140 -0.030724026 -9.481997e-01  0.0605133218
## 141  0.280790279 -7.115468e-01 -0.1807377792
## 142 -0.008787010  4.749768e-02 -0.0888962427
## 143  0.103527359  5.131972e-02 -0.0807659355
## 144 -0.201867693 -1.106181e+00  0.0891031469
## 145 -0.369311493 -1.262815e+00 -0.1912801448
## 146 -0.095224398 -5.265474e-01  0.8490330200
## 147 -0.360817115  2.215596e-01  0.0002232531
## 148 -0.035974046  3.295716e-01 -0.0715176794
## 149  0.695194193 -2.779100e-02  0.1387515830
## 150 -0.099697539  3.932585e-02 -0.1565618790
## 151  0.786122082  1.162813e-01 -0.0266310253
## 152 -0.628856008 -2.124479e-01  0.0248272164
## 153  1.502409582  2.723081e-01 -0.3774853945
## 154  0.008433250  1.505163e-01 -0.1390983703
## 155 -0.916833338  2.279070e-01 -0.2596300123
## 156 -0.801217938 -3.125560e-01  0.1640235078
## 157 -0.685583058  1.382482e-01 -0.8448194554
## 158  0.386325517 -8.047875e-02 -0.0937460783
## 159  0.208734699  1.981433e-01 -0.0261629190
## 160 -0.421021020  3.710247e-01 -0.0697303935
## 162 -0.445744514  3.056452e-01 -0.3151937467
## 163 -1.494337654  7.196649e-01 -0.4233680361
## 164 -1.154302648  9.511764e-01 -0.2575447687
## 165 -0.807523716 -3.265073e-01  0.0980454931
## 166 -0.745555826 -3.363478e-01  0.2273177465
## 167  0.145718774  7.221717e-02  0.0384099343
## 168  0.305071514  4.260211e-01  0.0264092174
## 169  0.756649520 -2.537995e-01 -0.4249850838
## 170  0.313089788 -1.779824e-01 -0.4725689619
## 171  0.160084703  1.171689e-01 -0.5567573363
## 172  0.072193615  2.537738e-01 -0.6898088438
## 173  0.280928028  8.606759e-03  0.0970974588
## 174  0.671409039 -1.367648e-01  0.0557193346
## 175 -0.021334113  6.023453e-01  0.0671180660
## 176  1.005588912  1.156397e-01 -0.2900808653
## 177  1.285263486  6.267489e-02  0.0036975951
## 178  0.431668081  1.825752e-01 -0.1063498524
## 179  0.867184070  9.718564e-02 -0.0252720909
## 180  1.145609839  6.976201e-02 -0.0117173938
## 181  0.592966482  1.061863e-01 -0.0870035693
## 182  0.906409226  1.330135e-01 -0.0337690997
## 183  0.658610833  1.161975e-01 -0.0364173668
## 185  0.370739768  2.089839e-01  0.0072082456
## 186 -0.220220861 -4.692873e-01  0.1493992369
## 187  0.716806636 -1.715167e-01  0.0552067301
## 188  0.437587059 -2.705809e-01 -0.1192106616
## 189  0.473754482 -9.207575e-02  0.0755528785
## 190  0.261493049 -2.000912e-01  0.0602616454
## 191  1.095277800 -4.634807e-02  0.1751504592
## 192  0.607176270  9.026465e-02  0.0378389680
## 193  0.398498631 -6.990289e-02  0.3729223930
## 194  0.385905916 -1.344080e-01 -0.0501557016
## 195  0.872699380 -3.688906e-01  0.0386993640
## 196  0.850737608 -5.304535e-01 -0.1021178178
## 197  0.576072118 -1.834781e-01  0.0575075110
## 198 -0.543092675  3.102720e-01 -0.2826833771
## 200  0.382534236 -1.415542e-01 -0.0150786289
algaetyp_pca2 <- cbind(data.frame(a2Cat),algae_pca$x)
algaetyp_pca3 <- cbind(data.frame(a3Cat),algae_pca$x)
algaetyp_pca4 <- cbind(data.frame(a4Cat),algae_pca$x)
algaetyp_pca5 <- cbind(data.frame(a5Cat),algae_pca$x)
algaetyp_pca6 <- cbind(data.frame(a6Cat),algae_pca$x)
algaetyp_pca7 <- cbind(data.frame(a7Cat),algae_pca$x)

T-test for PCA:

library(car)
## Loading required package: carData
t.test(PC1~algaeDataset$a1Cat,data=algaetyp_pca)
## 
##  Welch Two Sample t-test
## 
## data:  PC1 by algaeDataset$a1Cat
## t = 7.8119, df = 161.94, p-value = 6.696e-13
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  1.234850 2.070354
## sample estimates:
## mean in group Less mean in group More 
##           0.826301          -0.826301
t.test(PC2~algaeDataset$a1Cat,data=algaetyp_pca)
## 
##  Welch Two Sample t-test
## 
## data:  PC2 by algaeDataset$a1Cat
## t = -0.6213, df = 119.51, p-value = 0.5356
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.5082051  0.2654453
## sample estimates:
## mean in group Less mean in group More 
##        -0.06068993         0.06068993
t.test(PC3~algaeDataset$a1Cat,data=algaetyp_pca)
## 
##  Welch Two Sample t-test
## 
## data:  PC3 by algaeDataset$a1Cat
## t = 0.98186, df = 150.27, p-value = 0.3277
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.1658423  0.4934700
## sample estimates:
## mean in group Less mean in group More 
##         0.08190691        -0.08190691
t.test(PC4~algaeDataset$a1Cat,data=algaetyp_pca)
## 
##  Welch Two Sample t-test
## 
## data:  PC4 by algaeDataset$a1Cat
## t = 1.7282, df = 137.97, p-value = 0.0862
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.03215227  0.47819324
## sample estimates:
## mean in group Less mean in group More 
##          0.1115102         -0.1115102
t.test(PC5~algaeDataset$a1Cat,data=algaetyp_pca)
## 
##  Welch Two Sample t-test
## 
## data:  PC5 by algaeDataset$a1Cat
## t = -0.74733, df = 147.55, p-value = 0.4561
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.3289875  0.1484396
## sample estimates:
## mean in group Less mean in group More 
##        -0.04513696         0.04513696
t.test(PC6~algaeDataset$a1Cat,data=algaetyp_pca)
## 
##  Welch Two Sample t-test
## 
## data:  PC6 by algaeDataset$a1Cat
## t = -0.045498, df = 167.61, p-value = 0.9638
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.2143380  0.2046813
## sample estimates:
## mean in group Less mean in group More 
##       -0.002414193        0.002414193
t.test(PC7~algaeDataset$a1Cat,data=algaetyp_pca)
## 
##  Welch Two Sample t-test
## 
## data:  PC7 by algaeDataset$a1Cat
## t = -1.9193, df = 174.44, p-value = 0.05658
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.260408434  0.003637506
## sample estimates:
## mean in group Less mean in group More 
##        -0.06419273         0.06419273

F-test for PCA:

var.test(PC1~algaeDataset$a1Cat,data=algaetyp_pca)
## 
##  F test to compare two variances
## 
## data:  PC1 by algaeDataset$a1Cat
## F = 2.0862, num df = 91, denom df = 91, p-value = 0.000541
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  1.379658 3.154552
## sample estimates:
## ratio of variances 
##           2.086193
var.test(PC2~algaeDataset$a1Cat,data=algaetyp_pca)
## 
##  F test to compare two variances
## 
## data:  PC2 by algaeDataset$a1Cat
## F = 6.2232, num df = 91, denom df = 91, p-value = 2.22e-16
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  4.115546 9.410091
## sample estimates:
## ratio of variances 
##           6.223156
var.test(PC3~algaeDataset$a1Cat,data=algaetyp_pca)
## 
##  F test to compare two variances
## 
## data:  PC3 by algaeDataset$a1Cat
## F = 2.7002, num df = 91, denom df = 91, p-value = 3.605e-06
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  1.785688 4.082929
## sample estimates:
## ratio of variances 
##           2.700155
var.test(PC4~algaeDataset$a1Cat,data=algaetyp_pca)
## 
##  F test to compare two variances
## 
## data:  PC4 by algaeDataset$a1Cat
## F = 3.5964, num df = 91, denom df = 91, p-value = 3.678e-09
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  2.378376 5.438095
## sample estimates:
## ratio of variances 
##           3.596364
var.test(PC5~algaeDataset$a1Cat,data=algaetyp_pca)
## 
##  F test to compare two variances
## 
## data:  PC5 by algaeDataset$a1Cat
## F = 2.8699, num df = 91, denom df = 91, p-value = 9.306e-07
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  1.897970 4.339659
## sample estimates:
## ratio of variances 
##           2.869937
var.test(PC6~algaeDataset$a1Cat,data=algaetyp_pca)
## 
##  F test to compare two variances
## 
## data:  PC6 by algaeDataset$a1Cat
## F = 0.54678, num df = 91, denom df = 91, p-value = 0.004368
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  0.3616024 0.8267947
## sample estimates:
## ratio of variances 
##          0.5467824
var.test(PC7~algaeDataset$a1Cat,data=algaetyp_pca)
## 
##  F test to compare two variances
## 
## data:  PC7 by algaeDataset$a1Cat
## F = 1.5259, num df = 91, denom df = 91, p-value = 0.04521
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  1.009126 2.307341
## sample estimates:
## ratio of variances 
##           1.525909

Levene’s test for PCA with algae1:

(LTPC1_algae <- leveneTest(PC1~algaeDataset$a1Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value   Pr(>F)   
## group   1  7.4199 0.007079 **
##       182                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC2_algae <- leveneTest(PC2~algaeDataset$a1Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  2.4241 0.1212
##       182
(LTPC3_algae <- leveneTest(PC3~algaeDataset$a1Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value   Pr(>F)   
## group   1  8.5103 0.003976 **
##       182                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC4_algae <- leveneTest(PC4~algaeDataset$a1Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value   Pr(>F)   
## group   1  10.753 0.001247 **
##       182                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC5_algae <- leveneTest(PC5~algaeDataset$a1Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value   Pr(>F)    
## group   1  21.654 6.27e-06 ***
##       182                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC6_algae <- leveneTest(PC6~algaeDataset$a1Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value  Pr(>F)  
## group   1  6.5081 0.01156 *
##       182                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC7_algae <- leveneTest(PC7~algaeDataset$a1Cat,data=algaetyp_pca))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  2.6048 0.1083
##       182

Levene’s test for PCA with algae2:

(LTPC1_algae <- leveneTest(PC1~algaeDataset$a2Cat,data=algaetyp_pca2))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.3361 0.5628
##       182
(LTPC2_algae <- leveneTest(PC2~algaeDataset$a2Cat,data=algaetyp_pca2))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.0341 0.8537
##       182
(LTPC3_algae <- leveneTest(PC3~algaeDataset$a2Cat,data=algaetyp_pca2))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value  Pr(>F)  
## group   1  2.8616 0.09243 .
##       182                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC4_algae <- leveneTest(PC4~algaeDataset$a2Cat,data=algaetyp_pca2))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.0631  0.802
##       182
(LTPC5_algae <- leveneTest(PC5~algaeDataset$a2Cat,data=algaetyp_pca2))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.5538 0.4577
##       182
(LTPC6_algae <- leveneTest(PC6~algaeDataset$a2Cat,data=algaetyp_pca2))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.0305 0.8616
##       182
(LTPC7_algae <- leveneTest(PC7~algaeDataset$a2Cat,data=algaetyp_pca2))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.5315 0.4669
##       182

Levene’s test for PCA with algae3:

(LTPC1_algae <- leveneTest(PC1~algaeDataset$a3Cat,data=algaetyp_pca3))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.2599 0.6108
##       182
(LTPC2_algae <- leveneTest(PC2~algaeDataset$a3Cat,data=algaetyp_pca3))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.4843 0.4874
##       182
(LTPC3_algae <- leveneTest(PC3~algaeDataset$a3Cat,data=algaetyp_pca3))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.0728 0.7876
##       182
(LTPC4_algae <- leveneTest(PC4~algaeDataset$a3Cat,data=algaetyp_pca3))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  1.9103 0.1686
##       182
(LTPC5_algae <- leveneTest(PC5~algaeDataset$a3Cat,data=algaetyp_pca3))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.0484 0.8261
##       182
(LTPC6_algae <- leveneTest(PC6~algaeDataset$a3Cat,data=algaetyp_pca3))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.5406 0.4631
##       182
(LTPC7_algae <- leveneTest(PC7~algaeDataset$a3Cat,data=algaetyp_pca3))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  1.0675 0.3029
##       182

Levene’s test for PCA with algae4:

(LTPC1_algae <- leveneTest(PC1~algaeDataset$a4Cat,data=algaetyp_pca4))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  1.7754 0.1844
##       182
(LTPC2_algae <- leveneTest(PC2~algaeDataset$a4Cat,data=algaetyp_pca4))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  2.4405   0.12
##       182
(LTPC3_algae <- leveneTest(PC3~algaeDataset$a4Cat,data=algaetyp_pca4))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  2.0726 0.1517
##       182
(LTPC4_algae <- leveneTest(PC4~algaeDataset$a4Cat,data=algaetyp_pca4))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.7041 0.4025
##       182
(LTPC5_algae <- leveneTest(PC5~algaeDataset$a4Cat,data=algaetyp_pca4))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value  Pr(>F)  
## group   1   2.739 0.09965 .
##       182                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC6_algae <- leveneTest(PC6~algaeDataset$a4Cat,data=algaetyp_pca4))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value  Pr(>F)  
## group   1  2.9668 0.08669 .
##       182                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC7_algae <- leveneTest(PC7~algaeDataset$a4Cat,data=algaetyp_pca4))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value  Pr(>F)  
## group   1  2.7424 0.09944 .
##       182                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Levene’s test for PCA with algae5:

(LTPC1_algae <- leveneTest(PC1~algaeDataset$a5Cat,data=algaetyp_pca5))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  2.5008 0.1155
##       182
(LTPC2_algae <- leveneTest(PC2~algaeDataset$a5Cat,data=algaetyp_pca5))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.1026 0.7491
##       182
(LTPC3_algae <- leveneTest(PC3~algaeDataset$a5Cat,data=algaetyp_pca5))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value  Pr(>F)  
## group   1  3.0766 0.08111 .
##       182                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC4_algae <- leveneTest(PC4~algaeDataset$a5Cat,data=algaetyp_pca5))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.4938 0.4832
##       182
(LTPC5_algae <- leveneTest(PC5~algaeDataset$a5Cat,data=algaetyp_pca5))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1   1.288 0.2579
##       182
(LTPC6_algae <- leveneTest(PC6~algaeDataset$a5Cat,data=algaetyp_pca5))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value  Pr(>F)  
## group   1  5.5957 0.01906 *
##       182                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC7_algae <- leveneTest(PC7~algaeDataset$a5Cat,data=algaetyp_pca5))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.0044 0.9472
##       182

Levene’s test for PCA with algae6:

(LTPC1_algae <- leveneTest(PC1~algaeDataset$a6Cat,data=algaetyp_pca6))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  1.9162  0.168
##       182
(LTPC2_algae <- leveneTest(PC2~algaeDataset$a6Cat,data=algaetyp_pca6))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  2.4153 0.1219
##       182
(LTPC3_algae <- leveneTest(PC3~algaeDataset$a6Cat,data=algaetyp_pca6))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.4671 0.4952
##       182
(LTPC4_algae <- leveneTest(PC4~algaeDataset$a6Cat,data=algaetyp_pca6))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.2279 0.6337
##       182
(LTPC5_algae <- leveneTest(PC5~algaeDataset$a6Cat,data=algaetyp_pca6))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  1.4475 0.2305
##       182
(LTPC6_algae <- leveneTest(PC6~algaeDataset$a6Cat,data=algaetyp_pca6))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.4116 0.5219
##       182
(LTPC7_algae <- leveneTest(PC7~algaeDataset$a6Cat,data=algaetyp_pca6))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.0039 0.9505
##       182

Levene’s test for PCA with algae7:

(LTPC1_algae <- leveneTest(PC1~algaeDataset$a7Cat,data=algaetyp_pca7))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  1.6335 0.2029
##       182
(LTPC2_algae <- leveneTest(PC2~algaeDataset$a7Cat,data=algaetyp_pca7))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.1209 0.7285
##       182
(LTPC3_algae <- leveneTest(PC3~algaeDataset$a7Cat,data=algaetyp_pca7))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value  Pr(>F)  
## group   1  4.9291 0.02764 *
##       182                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(LTPC4_algae <- leveneTest(PC4~algaeDataset$a7Cat,data=algaetyp_pca7))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.0491 0.8248
##       182
(LTPC5_algae <- leveneTest(PC5~algaeDataset$a7Cat,data=algaetyp_pca7))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  0.0564 0.8126
##       182
(LTPC6_algae <- leveneTest(PC6~algaeDataset$a7Cat,data=algaetyp_pca7))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1  1.0612 0.3043
##       182
(LTPC7_algae <- leveneTest(PC7~algaeDataset$a7Cat,data=algaetyp_pca7))
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   1    1.88  0.172
##       182

The above test significance is summarized as follows: a1 <- PC1,PC3,PC4,PC5 and PC6 a2 <- no significance a3 <- no significance a4 <- no significance a5 <- PC6 a6 <- no significance a7 <- PC3

Scree Diagram:

From the below Scree diagram we conclude that upto PC5 it is significant to consider

plot(eigen_algaes, xlab = "Component number", ylab = "Component variance", type = "l", main = "Scree diagram")

plot(log(eigen_algaes), xlab = "Component number",ylab = "log(Component variance)", type="l",main = "Log(eigenvalue) diagram")

pairs(algae_pca$x[,1:7], ylim = c(-6,4),xlim = c(-6,4),panel=function(x,y,...){text(x,y,algaeDataset$a1Cat)})

With this we conclude that PCA is not right fit for this dataset since for the majority of the alage types the principal components are not significant also here we have only considered numerical category data type and not categorical datatype since that would also show some dependancy